{include file="public/header"}
</head>
<style>
    .layui-input {
        height: 28px;
        width: 50px;
    }
</style>

<body>
    <div class="cBody">
        <div class="console">
            <a class="layui-btn" onclick="OpenView('{:url('Goods/add')}','添加商品')">添加商品</a>
        </div>
        <table class="layui-table" id="demo" lay-filter="test">
            <script type="text/html" id="barDemo">
                <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="spec">设置规格</a>
                <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
            </script>
        </table>
    </div>
</body>
<script type="text/html" id="img">
    {{#  if(d.thum !=null){ }}
    <div><img src="{{d.thum}}" width="20" height="20" onclick="OpenImgs('{{d.thum}}')" /></div>
    {{#  } else { }}
        <div>暂无</div>
    {{#  } }}
</script>
<script type="text/html" id="barpinkage">
    {{#  if(d.is_pinkage =='1'){ }}
    <input type="checkbox" name="is_pinkage" data-id="{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="shortcuts" checked>
    {{#  } else { }}
    <input type="checkbox" name="is_pinkage" data-id="{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="shortcuts">
    {{#  } }}
</script>
<script type="text/html" id="barhot">
    {{#  if(d.is_hot =='1'){ }}
    <input type="checkbox" name="is_hot" data-id="{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="shortcuts" checked>
    {{#  } else { }}
    <input type="checkbox" name="is_hot" data-id="{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="shortcuts">
    {{#  } }}
</script>
<script type="text/html" id="barshow">
    {{#  if(d.is_show =='1'){ }}
    <input type="checkbox" name="is_show" data-id="{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="shortcuts" checked>
    {{#  } else { }}
    <input type="checkbox" name="is_show" data-id="{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="shortcuts">
    {{#  } }}
</script>
<script type="text/html" id="barPx">
    <input class="layui-input" type="tel" maxlength="3" oninput="value=value.replace(/[^\d]/g,'')" onblur="shortcuts('goods','{{d.id}}','px',this,'{:url('Login/shortcuts')}')" value="{{d.px}}">
</script>
<script>
    layui.use(['table', 'layer', 'form'], function () {
        var table = layui.table;
        var layer = layui.layer;
        var form = layui.form;
        form.render();
        form.on('switch(shortcuts)', function (data) {
            shortcuts('goods', $(this).attr('data-id'), this.name, this, "{:url('Login/shortcuts')}");
        });
        //第一个实例
        var datatable = table.render({
            elem: '#demo'
            , url: '{:url("Goods/list")}' //数据接口
            , method: 'POST'
            , cols: [[ //表头
                { field: 'title', title: '商品标题', sort: true },
                { field: 'name', title: '商品类型', sort: true },
                { field: 'thum', title: '缩略图', sort: true, templet: "#img" },
                { field: 'original_price', title: '原价', sort: true },
                { field: 'price', title: '售价', sort: true },
                { field: 'is_pinkage', title: '包邮', sort: true, templet: "#barpinkage" },
                { field: 'is_hot', title: '推荐', sort: true, templet: "#barhot" },
                { field: 'is_show', title: '显示', sort: true, templet: "#barshow" },
                { field: 'px', title: '排序', sort: true, templet: "#barPx" },
                { field: 'sales', title: '销量', sort: true },
                { field: 'add_date', title: '添加时间', sort: true, templet: '<div>{{ layui.laytpl.toDateString(d.add_date*1000) }}</div>' },
                { field: 'rep_date', title: '更新时间', sort: true, templet: '<div>{{ layui.laytpl.toDateString(d.rep_date*1000) }}</div>' },
                { field: 'right', title: '操作', toolbar: "#barDemo", fixed: 'right', width: '190' }
            ]]
            , page: true
        });
        //监听工具条
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                // console.log(data.id);
                del('{:url("Goods/del")}', data.id, obj);
            } else if (obj.event === 'edit') {
                OpenView('{:url("Goods/edit")}?id=' + data.id, '编辑');
            } else if (obj.event === 'spec') {
                OpenView('{:url("Goods/spec")}?id=' + data.id, '规格');
            }
        });
        // 执行搜索，表格重载
        $('#do_search').on('click', function () {
            // 搜索条件
            var name = $('#name').val();
            var keywords = $('#keywords').val();
            table.reload('demo', {
                method: 'post'
                , where: {
                    keywords: name,
                }
                , page: true
            });
        });
    });

</script>
{include file="public/footer"}